<?php
namespace app\index\controller;
use think\Request;
use think\Response;
use think\exception\HttpResponseException;
class Base{
	protected $request;
	/**
     * 构造方法
     * @access public
     * @param Request $request Request 对象
     */
    public function __construct(Request $request = null)
    {
        $this->request = is_null($request) ? Request::instance() : $request;
    }
	public function success($data=null){
		$result=['success'=>true,
            	'data'=>$data
	];
		$this->result($result);
	
	}
	public function error($errorCode='404',$errorMessage='返回错误'){
		$result=['success'=>false,
              'errorCode'=>$errorCode,
              'errorMessage'=>$errorMessage
	];
		$this->result($result);
	}
	public function result($data=null){
		$response=Response::create($data,'json',200);
		throw new HttpResponseException($response);
	}
}